package com.rs.config;

import com.rs.entity.login.User;
import lombok.Data;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

public class CurrentUser {

    private static String userName;
    private static String userId;

    public static String getUserName() {
        return getCurrentUser().getUsername();
    }

    public static Integer getUserId() {
        return getCurrentUser().getId();
    }

    static User getCurrentUser() {

        HttpServletRequest request =
                ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        HttpSession session = request.getSession();
        User user=(User)session.getAttribute("user");

        return user;
    }
}
